package cn.zhc.com.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;



/**
 * Created by zhouhongchun on 2017/9/6.
 */

public class UtilDialog {
    /**
     * 使用默认布局样式
     * @param context
     * @param title
     * @param message
     * @param positiveText
     * @param negativeText
     * @param mOnCustomDialogListener
     */
    public static Dialog showCustomAlertDialog(Context context,String title,String message,String positiveText,String negativeText,CustomAlertDialog.OnCustomDialogListener mOnCustomDialogListener){
        return new CustomAlertDialog
                .Builder(context)
                .addTitle(title)
                .addMessage(message)
                .addPositiveText(positiveText)
                .addNegativeText(negativeText)
                .addOnCustomDialogListener(mOnCustomDialogListener)
                .build();
    }

    /**
     * @param view 新的布局，请注意控件命名方式必须通默认布局
     * @param context
     * @param title
     * @param message
     * @param positiveText
     * @param negativeText
     * @param mOnCustomDialogListener
     */
    public static Dialog showCustomAlertDialogWithView(View view,Context context, String title, String message, String positiveText, String negativeText, CustomAlertDialog.OnCustomDialogListener mOnCustomDialogListener){
        return new CustomAlertDialog
                .Builder(context)
                .addView(view)
                .addTitle(title)
                .addMessage(message)
                .addPositiveText(positiveText)
                .addNegativeText(negativeText)
                .addOnCustomDialogListener(mOnCustomDialogListener)
                .build();
    }

    /**
     * 显示进度条弹框
     * @param context
     * @param text
     * @return
     */
    public static Dialog showProgressDialog(Context context, String text) {
        CustomProgressDialog dialog = new CustomProgressDialog(context);
        //dialog弹出后会点击屏幕或物理返回键，dialog不消失
        dialog.setCancelable(false);
        //dialog弹出后会点击屏幕，dialog不消失；点击物理返回键dialog消失
        dialog.setCanceledOnTouchOutside(false);
        if (!dialog.isShowing()) {
            dialog.show();
            dialog.setDialogText(text);
        }
        return dialog;
    }
    /**
     * 关闭弹窗
     * @param mDialog
     */
    public static void dismissDialog(Dialog mDialog){
        if (mDialog!= null && mDialog.isShowing()){
            mDialog.dismiss();
        }

    }
}
